package com.aaa.service.impl;

import cn.hutool.core.lang.tree.Tree;
import cn.hutool.core.lang.tree.TreeNodeConfig;
import cn.hutool.core.lang.tree.TreeUtil;
import com.aaa.dao.MenuDao;
import com.aaa.dao.impl.MenuDaoImpl;
import com.aaa.entity.MenuTree;
import com.aaa.service.MenuService;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @author ：Teacher陈
 * @date ：Created in 2020/10/29 16:00
 * @description：菜单业务实现类
 * @modified By：
 * @version: 1.0
 */
public class MenuServiceImpl  implements MenuService {
    MenuDao menuDao= new MenuDaoImpl();
    @Override
    public List<Map<String, Object>> findAllMenu(Map<String, String> map) {
        return menuDao.findAllMenu(map);
    }

    @Override
    public List<MenuTree> findMenuTree(Map<String, String> map) {
        List<Map<String, Object>> allMenu = menuDao.findAllMenu(map);
        TreeNodeConfig treeNodeConfig = new TreeNodeConfig();
        // 自定义属性名 都要默认值的
        treeNodeConfig.setWeightKey("order");
        treeNodeConfig.setIdKey("rid");
        // 最大递归深度
        treeNodeConfig.setDeep(2);
        List<Tree<String>> treeNodes = TreeUtil.build(allMenu, "0", treeNodeConfig,
                (menu, tree) -> {
                    tree.setId(menu.get("menu_id").toString());
                    tree.setParentId(menu.get("parent_id").toString());
                    tree.setWeight(menu.get("order_num").toString());
                    tree.setName(menu.get("menu_name").toString());
                    // 扩展属性 ...
                    tree.putExtra("extraField", 666);
                    tree.putExtra("other", new Object());
                });
        return null;
    }
}
